<?php
session_start();
create_image();
exit();
function create_image()
{
	$md5_hash = md5(rand(0,999)); //tao mot bien so md5_hash de luu ki tu ngau nhien 
	$security_code = substr($md5_hash, 15, 5); //cat chuoi
	$_SESSION["security_code"] = $security_code; // gan ma code da cat vao session
	$width = 100;
	$height = 30;
	$image = ImageCreate($width,$height); // tao images voi width la 100 va height la 30
	$white = ImageColorAllocate($image,255,255,255);//ImageColorAllocate($image, red, green, blue )
	$black = ImageColorAllocate($image,0,0,0);
	ImageFill($image,0,0,$black); // do nen cho tam hinh mau den
	ImageString($image,5,30,6,$security_code,$white);// do chu cho tam hinh la mau trang, 5:font-size, 30:khoang cach trai, khoang cach tren
	header("Content-Type: image/jpeg");// chon kieu hinh la jpeg
	ImageJpeg($image);
	ImageDestroy($image);
}

?>

